package baiduyun;

import com.alibaba.fastjson.JSONObject;
import com.baidu.aip.face.AipFace;
import com.jn.exam.HTMLUtil;
import com.jn.exam.MD5Util;
import com.jn.exam.UUIDUtil;
import com.jn.exam.oss.utils.GetToken;
import org.junit.Test;

import javax.print.DocFlavor;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashMap;
import java.util.List;

/**
 * @author 江南大学1033190417
 * @date 2022/1/9 23:39
 */
public class Sample {
//    @Test
//    public void Sample(){
//        // 传入可选参数调用接口
//        HashMap<String, String> options = new HashMap<String, String>();
//        options.put("face_field", "age");
//        options.put("max_face_num", "2");
//        options.put("face_type", "LIVE");
//        options.put("liveness_control", "LOW");
//
//        //初始化一个ApiFace
//        AipFace client=new AipFace(ConstantPropertiesUtil.APP_ID,ConstantPropertiesUtil.API_KEY,ConstantPropertiesUtil.SECRET_KEY);
//        //设置网络连接参数
//        client.setConnectionTimeoutInMillis(2000);
//        client.setSocketTimeoutInMillis(60000);
//
//        String image="";
//        String imageType="BASE64";
//
//        //人脸检测
//        JSONObject res=client.detect(image,imageType,options);
//    }

    //测试获取token
    @Test
    public void testGetToken() {
        long start = System.currentTimeMillis();
        String token = GetToken.getAuth("Co8aftCOimcGqS44xn1ec0i4", "Wjc5LtEdZbMng0YsSvEV5pGr9Lf2Z7TI");
        System.out.println("耗时====" + (System.currentTimeMillis() - start));
        System.out.println("======" + token);
    }

    //测试UUID
    @Test
    public void testUUID() {
        System.out.println(UUIDUtil.getUUID());
    }

    //测试MD5
    @Test
    public void testMD5() {
        System.out.println(MD5Util.getMD5("123456"));
    }

    //测试获取文件后缀
    @Test
    public void getFileType() {
        String fileName = "abc.jpg";
        String type = fileName.substring(fileName.lastIndexOf("."));
        System.out.println("========" + type);

    }

    @Test
    public void testUrl() {
        String html = "<video src=\"https://msjava.oss-cn-qingdao.aliyuncs.com/2022/01/25/dc1a9eff0cde4bb29f066f296495fcf4.jpg\">" +
                "<img src=\"https://msjava.aliyuncs.com/2022/01/25/dc1a9eff0cde4bb29f066f296495fcf4.jpg\">";
        long start = System.currentTimeMillis();
        List<String> imgStr = HTMLUtil.getUrl(html);
        System.out.println(imgStr);
        System.out.println("***************************");
        for (String url:imgStr){
            html=html.replaceAll(url,"https://msjava.oss-cn-qingdao/newFile");
        }
        long end = System.currentTimeMillis();
        System.out.println("耗时："+(end-start));
        System.out.println(html);

    }

    @Test
    public void testgetHtmlText(){
        String html = "<video src=\"你好https://msjava.oss-cn-qingdao.aliyuncs.com/2022/01/25/dc1a9eff0cde4bb29f066f296495fcf4.jpg\">五月" +
                "<img src=\"https://msjava.oss-cn-qingdao.aliyuncs.com/2022/02/14/85492bb489284fd1bb0a711d9da4c861.jpg\">"+"<p>sa傻逼</p>";
        long start = System.currentTimeMillis();
        System.out.println(HTMLUtil.getHtmlText(html));
        long end = System.currentTimeMillis();
        System.out.println("耗时："+(end-start));

    }
    @Test
    public void test01() throws MalformedURLException {
        String html = "https://msjava.oss--qingdao.aliyuncs.com/2022/01/25/dc1a9eff0cde4bb29f066f296495fcf4.jpg";
        URL url=new URL(html);
        System.out.println(url.getFile());

    }
}
